package com.wangc.report.controller;

import com.wangc.report.entity.TragetTableEntity;
import com.wangc.report.service.TragetTableService;
import com.wangc.report.utils.PageUtils;
import com.wangc.report.utils.Query;
import com.wangc.report.utils.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Controller
 *
 * @author wangc
 * @email 1620415297@qq.com
 * @date 2020-10-20 14:14:15
 */
@RestController
@RequestMapping("tragettable")
public class TragetTableController {
    private static final Logger LOG = LoggerFactory.getLogger(TragetTableController.class);
    @Autowired
    private TragetTableService tragetTableService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        LOG.debug(params.toString());
        List<TragetTableEntity> tragetTableList = tragetTableService.queryList(query);
        int total = tragetTableService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(tragetTableList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        TragetTableEntity tragetTable = tragetTableService.queryObject(id);

        return R.ok().put("tragetTable", tragetTable);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TragetTableEntity tragetTable) {
        tragetTableService.save(tragetTable);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TragetTableEntity tragetTable) {
        tragetTableService.update(tragetTable);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        tragetTableService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<TragetTableEntity> list = tragetTableService.queryList(params);

        return R.ok().put("list", list);
    }
}
